{% extends 'base.html' %}
{% block title %}
    <a class="navbar-brand" href="{{ url_for('report_form') }}">{% if departmentID == 0 %}全部{% else %}{% for department in departments %}{{ department.departmentname }}{% endfor %}{% endif %} 部门离职员工报表 </a>
{% endblock %}
{% block content %}
    {# 使用 length 过滤器获取 staffs 变量的长度 #}
    {% if current_user.has_role('Admin') or current_user.has_role('Root') %}
        <div class="content">
            <h4 class="title">{% if departmentID == 0 %}全部{% else %}{% for department in departments %}{{ department.departmentname }}{% endfor %}{% endif %} 部门离职员工报表</h4>
            <div class="toolbar">
                <!--        Here you can write extra buttons/actions for the toolbar              -->
                <form method="post">
                    <div class="col-sm-6" style="width: auto;">
                        选择统计开始日期<input type="date" name="begin_date"  autocomplete="off" required>
                    </div>
                    <div class="col-sm-6" style="width: auto">
                    选择统计结束日期<input type="date" name="end_date"  autocomplete="off" required>
                    </div>
                    <div >
                    <input type="submit" name="submit" value="查询">
                    </div>
                </form>

            </div>
                <div class="card-footer text-center" style="margin-top: 10px">
                            <input type="button" name="submit" class="btn" value="导出">
						</div>
                <div class="newstaff material-datatables">
                    <table id="newstaff" class="table table-striped table-no-bordered table-hover"
                           style="width:100%;cellspacing:0">
                        <thead>
                        <tr>
                            <th>员工号</th>
                            <th>姓名</th>
                            <th>部门</th>
                            <th>岗位</th>
                            <th>性别</th>
                            <th>离职日期</th>
                            <th>离职原因</th>
                        </tr>
                        </thead>

                        <tbody>
                        {% for staff in staffs %}
                            {% for  department in departments%}
                                {% for post in posts %}
                                    {% for staff_dimission in staff_dimissions %}
                                {% if department.departmentID == staff.departmentID and staff.postID == post.postID and staff.userID==staff_dimission.userID%}
                                <tr>
                                    <td>{{ staff.userID }}</td>
                                    <td>{{ staff.username }}</td>
                                    <td>{{ department.departmentname }}</td>
                                    <td>{{ post.postname }}</td>
                                    <td>{{ staff.sex }}</td>
                                    <td>{{ staff_dimission.termdate }}</td>
                                    <td>{{ staff_dimission.dimission_type }}</td>
                                </tr>
                                {% endif %}
                                        {% endfor %}
                                {% endfor %}
                            {% endfor %}
                        {% endfor %}
                        </tbody>

                    </table>

                </div>
        </div>
    {% endif %}
    <script type="text/javascript">
            $(function() {
                $(".btn").click(function(){
                    $(".newstaff").table2excel({
                        // 不被导出的表格行的CSS class类
                        exclude: ".noExl",
                        // 导出的Excel文档的名称
                        name: "Excel Document Name",
                        // Excel文件的名称
                        filename: "{% if departmentID == 0 %}全部{% else %}{% for department in departments %}{{ department.departmentname }}{% endfor %}{% endif %}部门离职员工报表",
                        //文件后缀名
                        fileext: ".xls",
                        //是否排除导出图片
                        exclude_img: true,
                        //是否排除导出超链接
                        exclude_links: true,
                        //是否排除导出输入框中的内容
                        exclude_inputs: false
                    });
                });
            });
    </script>
{% endblock %}